/**
 * 学习目标：使用setState修改状态
 *
 *
 */
import React from 'react';
import ReactDOM from 'react-dom';

class App extends React.Component {
  state = {
    count: 0,
    msg: '123',
  };
  render() {
    return (
      <div>
        我是APp
        <h1>{this.state.count}</h1>
        <button onClick={this.handleAdd}>点我加1</button>
      </div>
    );
  }

  handleAdd = () => {
    console.log('this  ----->  ', this.state.count);
    // ✅正确的写法
    this.setState({ count: this.state.count + 1 });
    // 不可变数据 - 不能直接直接对state的属性赋值
    // ❌错误的写法
    // this.state.count++;
    // this.state.count = this.state.count + 1;
    // this.setState({
    //   count: this.state.count++,
    // });
  };
}

ReactDOM.render(<App></App>, document.getElementById('root'));
